<template>
  <van-list
    :finished="finished"
    @load="onLoad"
    finished-text="没有更多了"
    v-model="loading"
  >
    <article-item
      :article="article"
      :key="index"
      v-for="(article, index) in list"
      @click.native="$router.push(`/article/${article.art_id}`)"
    />
  </van-list>
</template>

<script>
import {
  getUserCollectArticles,
  getUserHistoryArticles
} from "../../../network/article";
import ArticleItem from "../../home/chi-coms/article-item";

export default {
  name: "LoadList",
  props: ["type"],
  components: { ArticleItem },
  computed: {},
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      perPage: 10
    };
  },
  created() {
    // console.log("加载");
  },
  mounted() {},
  methods: {
    async onLoad() {
      if (this.type === 0) {
        const result = await getUserCollectArticles({
          page: this.page,
          perPage: this.perPage
        });
        console.log(result);
        const { results } = result.data;
        this.list.push(...results);
        this.page++;
        this.loading = false;
        if (results.length < 10) {
          this.finished = true;
        }
      } else {
        const result = await getUserHistoryArticles({
          page: this.page,
          perPage: this.perPage
        });
        // console.log(result);
        const { results } = result.data;
        this.list.push(...results);
        this.page++;
        this.loading = false;
        if (results.length < 10) {
          this.finished = true;
        }
      }
    }
  }
};
</script>

<style scoped lang="stylus" ></style>  